package com.ykq.product.controller;

import com.ykq.Product;
import com.ykq.product.service.ProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("product")
@Slf4j
public class ProductController {
    @Autowired
    private ProductService productService;
    @GetMapping("findById/{pid}") //不要再方法上@RequestMapping
    public Product findById(@PathVariable("pid")Integer pid){
        if(pid==2){
            throw new RuntimeException("id号不能为2");
        }
        Product product = productService.findById(pid);
        return product;
    }
}
